package com.mysoft.gfyx.common.rpc.omp.impl;

import com.mysoft.gfyx.common.rpc.omp.OMPClientConfiguration;
import com.mysoft.gfyx.common.rpc.omp.OMPClientFactoryService;
import com.mysoft.gfyx.common.rpc.omp.OMPClientService;
import feign.Feign;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class OMPClientFactoryServiceImpl implements OMPClientFactoryService {

    @Value("${omp.host}")
    private String host;

    @Value("${omp.auth-host}")
    private String authHost;

    @Value(("${omp.client-secret}"))
    private String clientSecret;

    public OMPClientService getOMPService() {
        OMPClientService ompClientService = Feign.builder()
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .requestInterceptor(new OMPClientConfiguration(authHost, clientSecret))
                .target(OMPClientService.class, host);

        return ompClientService;
    }
}
